*** Settings ***
Documentation    TC12-Project Status Check AIR
Resource    ../../Keywords/Common_Head.robot
Resource    ../../Keywords/Common/Common_kw.robot
Force Tags    P3
Metadata    Author    Bella
Metadata    ID    13566

*** Test Cases ***
TC12-Project Status Check AIR
    Step 1 Create Tender
    Step 2 Create Project
    Step 3 Check The Status Of Project
    Step 4 Select Project and Do Data Cleaning
    Step 5 Upload Attachments
    Step 6 Check Mapping and Summary
    Step 7 Check Project Status in Step7  ## stay in step7
    Step 8 Process and Check Project Status in Step8
    Step 9 Process Round Management to Started
    Step 10 Process Round Management to Closed
    Step 11 Process Round Management to Not Started
    Step 12 Process Round Management to Closed in Step12
    Step 13 Reactive
    Step 14 Close Project
    Step 15 Reactive Project
    Step 16 Process Lane Management
    Step 17 Submit Reactive
    Step 18 Close Project in Step18
    Step 19 Reopen Project
    Step 20 Data Cleaning 
    # Step 21 Delete Tender



*** Keywords ***
Step ${step} Create Tender
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    Login Space
    ${G_TENDERID}    Generate Tender ID
    ${TenderTitle}   Set Variable    Regression_AIRMODE_TC12-Project
    Set Suite Variable     ${G_TENDERID}    ${G_TENDERID}
    Set Suite Variable     ${TenderTitle}    ${TenderTitle}
    Create Tender    ${G_TENDERID}    ${TenderTitle}    815    true    true    true

Step ${step} Create Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #      Input following attributes
    #      Tender ID 20240815 Regression
    #      Mode Air
    #      Deadline to TM current date 10 day
    #      Rate Validity From current date
    #      Rate Validity To current date 100 day
    #      Deputies NATZHANG
    #      Description for regression
    #      Click on Save button
    #  Expected:
    #      A new project is created successfully
    #************************************************************
    ${DeadLine}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    ${ValidFrom}    Get Current Date    UTC    result_format=%d/%m/%Y
    ${ValidTo}    Get Current Date    UTC    +100days    result_format=%d/%m/%Y
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}    
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=${TenderTitle}    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
          ...   MODE=AIR    DEADLINE_TM_DATE=${DeadLine}    VALID_FROM=${ValidFrom}    VALID_TO=${ValidTo}    DEPUTY=NATZHANG
    Set Test Variable    ${PROJECT}    ${PROJECT}
    Create Project    ${PROJECT}

Step ${step} Check The Status Of Project
    #************************Step 3******************************
    #  Do:
    #      Check the Status of this new created project
    #  Expected:
    #      Status In Progress
    #      Pricing Round Number blank
    #      Pricing Round Status blank
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    In Progress  
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     ${EMPTY}
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    ${EMPTY}  


Step ${step} Select Project and Do Data Cleaning
    #************************Step 4******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks data cleaning button
    #  Expected:
    #      A dialogue named 20240815 AIR Regression shows
    #     successfully
    #************************************************************
    click    ${Project_toolbar_DataCleaningButton}
    Wait For Elements State    //h4[contains(text(),'${G_TENDERID}')]      visible    20

Step ${step} Upload Attachments
    #************************Step 5******************************
    #  Do:
    #      Click on Upload button select the attachment to upload
    #     index php attachments get 0eac5e4d 0b66 4c75 951e
    #     ca0aeee548bd
    #  Expected:
    #      Upload successfully
    #************************************************************
    Click    ${Data_toolbar_UploadButton}
    Wait For Elements State    ${Data_Upload_AddFile}    enabled    60
    ${Data_Upload_AddFile1}    Set Variable    xpath=//input[@name='file']
    Upload File By Selector    ${Data_Upload_AddFile1}    ${CURDIR}${/}TestData${/}TC12-AirTemplate-Location-All.xlsx
    Wait For Elements State    xpath=//label[.='Document Name']    visible    30 


Step ${step} Check Mapping and Summary
    #************************Step 6******************************
    #  Do:
    #      User select map columns like that
    #      Origin Country country from F
    #      Destination Country country to I
    #      Origin City city from E
    #      Destination City city to H
    #      Origin State state from G
    #      Destination State state to J 
    #      Schenker Service Level Schenker Service Level C
    #      MD LD MD LD K
    #      Click on Start button
    #  Expected:
    #      Step3
    #      Summary Successful
    #      Please close this page and go to Generate Internal
    #     Pricing Template
    #************************************************************
    Select Options By   ${FCL/AIR_Select_OriginCountry}    label    ${SPACE}${SPACE}country from - F    Country from - F
    Select Options By   ${FCL/AIR_Select_DestinationCountry}      label     ${SPACE}${SPACE}country to - I        Country to - I
    Select Options By   ${Origin_City}      label     ${SPACE}city from - E
    Select Options By   ${Destination_City}      label      ${SPACE}${SPACE}city to - H
    Select Options By   ${Origin_State}      label    State From - G    State from - G
    Select Options By   ${Destination_State}      label    State To - J
    Select Options By   ${DB_Schenker_Service_Level}      label    Schenker Service Level - C
    Select Options By   ${MD/LD}      label    MD/LD - K
    click    ${Data_toolbar_StartButton}
    Wait For Elements State    ${Data_toolbar_DownloadButton}    visible    30 
    Wait For Elements State   ${Data_toolbar_UploadAfterStartButton}    visible
    Wait For Elements State    ${Data_toolbar_SetPassButton}     visible
    Wait Until Search Finished
    ${content}    Get Text    //div[@class="row form-group col-md-12 ng-scope"][2]
    Should Contain    ${content}    Summary: Successful
    Should Contain    ${content}    Please close this page and go to Generate Internal Pricing Template.

Step ${step} Check Project Status in Step7
    #************************Step 7******************************
    #  Do:
    #      Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status In Progress
    #      Pricing Round Number blank
    #      Pricing Round Status blank
    #************************************************************
    Click    ${Data_toolbar_CloseButton}
    Click    [data-ng-click="onButtonClick(button)"]
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    In Progress  
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     ${EMPTY}
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    ${EMPTY}  

Step ${step} Process and Check Project Status in Step8
    #************************Step 8******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks template management button
    #      In the pop up dialog click on Start button in Step3
    #     click on Skip button in step4
    #      And then click on Close button to Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status In Progress
    #      Pricing Round Number 1
    #      Pricing Round Status Not Started
    #************************************************************
    Click    //tbody/tr[1]
    Click    ${Project_toolbar_TemplateManagementButton}
    Wait For Elements State    [data-ng-click="generateInternalTemplate()"]    visible    30 
    click    [data-ng-click="generateInternalTemplate()"]
    Wait For Elements State    css=[data-ng-click="downloadGeneratedTemplate()"]    visible    30 
    ${filename}    Download File    css=[data-ng-click="downloadGeneratedTemplate()"]
    Open Excel Document    ${filename}    AIR_D
    Write Excel Cell    5    50    TEST     AIR_D
    Write Excel Cell    6    50    TEST     AIR_D
    Save Excel Document   ${filename} 
    Close All Excel Documents    
    Reopen And Save Excel    ${filename} 
    Sleep    5
    click    [data-ng-click="uploadInternalPricingTemplate()"]
    Wait For Elements State   ${upload_addFileButton}     enabled
    Upload File By Selector    ${upload_addFileButton}    ${filename}
    click    ${Template_SkipSendToGPDButton}
    click    ${SkipSendToGPD_Yes}
    Wait For Elements State    css=[data-ng-click="go2NextStep()"]   enabled    20
    click   [data-ng-click="closeInternalTemplatePage()"]
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    In Progress  
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     1
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Not Started 

Step ${step} Process Round Management to Started
    #************************Step 9******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks round management button
    #      In the pop up dialog, set deadline for each region as current date
    #     assign some users WENDJIAN to all
    #     the regions start round send notification
    #      And then click on Close button to Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 1
    #      Pricing Round Status Started
    #************************************************************
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    //a[.='Regional']    visible    30 
    Input Deadline In Region Tab   0    0
    Input Deadline In Region Tab    0    1
    Input Deadline In Region Tab    1    0
    CLICK    [data-ng-click="addUserToAssignment()"]
    Round Mgmt Assign User    //a[.='APAC']   xpath=//div[@data-model='availableItems']//ul//li//b[.='Wendy Jiang (WENDJIAN)']
    Round Mgmt Assign User    //a[.='EUROPE']   xpath=//div[@data-model='availableItems']//ul//li//b[.='Wendy Jiang (WENDJIAN)']
    Round Mgmt Assign User    //a[.='NAM']   xpath=//div[@data-model='availableItems']//ul//li//b[.='Wendy Jiang (WENDJIAN)']
    click    ${Project_RoundMgmt_Assign_SaveButton} 
    click    ${Project_RoundMgmt_StartButton} 
    click    ${Project_RoundMgmt_StartConfirmButton}
    click    ${Project_RoundMgmt_Confirm_SendButton}
    click    ${Project_RoundMgmt_CloseButton}
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     1
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Started

Step ${step} Process Round Management to Closed
    #************************Step 10******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks round management button
    #      In the pop up dialog Click Close Round do not send
    #     notification to anyone click on Yes
    #      And then click on Close button to Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 1
    #      Pricing Round Status Closed
    #************************************************************
    Click    ${Project_toolbar_RoundMgmtButton}
    click    ${Project_RoundMgmt_CloseRoundButton} 
    click    ${Project_RoundMgmt_StartConfirmButton} 
    CLICK    ${Project_RoundMgmt_CloseButton}
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     1
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed

Step ${step} Process Round Management to Not Started
    #************************Step 11******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks round management button
    #      In the pop up dialog Click New Round
    #      And then click on Close button to Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 2
    #      Pricing Round Status Not Started
    #************************************************************
    Click    ${Project_toolbar_RoundMgmtButton}
    click    ${Project_RoundMgmt_NewRoundButton}
    CLICK    //button/span[.='Yes']
    CLICK    ${Project_RoundMgmt_CloseButton}
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Not Started

Step ${step} Process Round Management to Closed in Step12
    #************************Step 12******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks round management button
    #      In the pop up dialog,set deadline for each region as current date
    #     assign some users WENDJIAN to all
    #     the regions start round send notification close Round do
    #     not send notification to anyone click on Yes
    #      And then click on Close button to Close this dialog
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    //a[.='Regional']    visible    30 
    Input Deadline In Region Tab   0    0
    Input Deadline In Region Tab    0    1
    Input Deadline In Region Tab    1    0
    click    ${Project_RoundMgmt_StartButton} 
    click    ${Project_RoundMgmt_StartConfirmButton}
    click    ${Project_RoundMgmt_Confirm_SendButton}
    click    ${Project_RoundMgmt_CloseRoundButton}
    click    ${Project_RoundMgmt_StartConfirmButton}
    # click   ${Project_RoundMgmt_StartConfirmButton}
    CLICK    ${Project_RoundMgmt_CloseButton}
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed

Step ${step} Reactive
    #************************Step 13******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Submit Reactive button
    #      In the confirm window click on Yes
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Submitted to Customer
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    click    ${Project_toolbar_Submit/ReactivateButton} 
    Click    [data-ng-click="onButtonClick(button)"]
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Submitted to Customer 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed

Step ${step} Close Project
    #************************Step 14******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Close Project button
    #  Expected:
    #      Failed with the error message Your tender cannot be
    #     closed until the award information has been uploaded for
    #     all lanes Please update your IPT accordingly and try
    #     again
    #************************************************************
    click    ${Project_toolbar_CloseButton}
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains        Your tender cannot be closed until the award information has been uploaded for all lanes. Please update your IPT accordingly and try again.

Step ${step} Reactive Project
    #************************Step 15******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Submit Reactive button
    #      In the confirm window click on Yes
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    click    ${Project_toolbar_Submit/Reactivate Project}
    click    [data-ng-click="onButtonClick(button)"]
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed

Step ${step} Process Lane Management
    #************************Step 16******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Lane Management button
    #      Update Existing Lanes
    #      Download the IPT update the value of DB Schenker
    #      Awarded Lane as following and then upload it
    #      index php attachments get 1000386641
    #  Expected:
    #      Successfully uploaded
    #************************************************************
    click    ${Project_toolbar_LaneManagementButton}
    Click If Enabled    ${Project_LaneMgmt_NextButton}
    ${filename}    Download File    ${Project_LaneMgmt_UpdateLane_DownloadButton} 
    Wait Until Search Finished
    Open Excel Document    ${filename}    AIR_D
    Write Excel Cell    5    13    N    AIR_D
    Write Excel Cell    6    13    N     AIR_D
    Save Excel Document   ${filename}
    Close All Excel Documents
    Reopen And Save Excel    ${filename} 
    click    ${Project_LaneMgmt_UpdateLane_UploadButton}
     Wait For Elements State   ${upload_addFileButton}     enabled
    Upload File By Selector    ${upload_addFileButton}    ${filename}
    CLICK    ${Project_LaneMgmt_UpdateLane_CloseButton} 

Step ${step} Submit Reactive
    #************************Step 17******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Submit Reactive button
    #      In the confirm window click on Yes
    #      Refresh the current page of pricing project
    #      Check the Status of this new created project
    #  Expected:
    #      Status Submitted to Customer
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID}
    click    ${Project_toolbar_Submit/ReactivateButton} 
    click    [data-ng-click="onButtonClick(button)"]
     Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Submitted to Customer 
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed


Step ${step} Close Project in Step18
    #************************Step 18******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Close Project button
    #      In the confirm window click on Yes
    #      Search out this project by project name
    #      Check the Status of this new created project
    #  Expected:
    #      Status Closed
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    click    ${Project_toolbar_CloseButton}
    click    [data-ng-click="onButtonClick(button)"]
    Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Closed
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed


Step ${step} Reopen Project
    #************************Step 19******************************
    #  Do:
    #      User select the row which project name is 20240815 AIR
    #     Regression clicks Reopen Project button
    #      In the confirm window click on Yes
    #      Search out this project by project name
    #      Check the Status of this new created project
    #  Expected:
    #      Status Active
    #      Pricing Round Number 2
    #      Pricing Round Status Closed
    #************************************************************
    click    ${Project_toolbar_ReopenProject}
    click    [data-ng-click="onButtonClick(button)"]
     Search Project    ${PROJECT.TENDER_ID}  
    ${Status}    get Text   //tr[@data-action-menu="action"]//td[7]  
    Should Be Equal    ${Status}    Active
    ${Pricing Round Number}    get Text   //tr[@data-action-menu="action"]//td[8]  
    Should Be Equal    ${Pricing Round Number}     2
    ${Pricing Round Status}    get Text   //tr[@data-action-menu="action"]//td[9]  
    Should Be Equal    ${Pricing Round Status}    Closed

Step ${step} Data Cleaning 
    #************************Step 20******************************
    #  Do:
    #      User click on Data Cleaning of this project and then
    #     cancel it Delete this project
    #  Expected:
    #      The project can be deleted successfully
    #************************************************************
    click    ${Project_toolbar_DataCleaningButton}
    click    [data-ng-click="onButtonClick(button)"]
    CLICK    ${Data_toolbar_CloseButton}
    CLICK    [data-ng-click="onButtonClick(button)"]
    Search Project    ${PROJECT.TENDER_ID} 

# Step ${step} Delete Tender 
    #************************Step 21******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    ### done in tear down


